﻿<UserControl x:Class="DotBeer.UI.WPFClient.ItemsCollectionControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="Auto" 
    Width="Auto" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:business="clr-namespace:DotBeer.Business.Entities;assembly=DotBeer.Business.Entities"
    xmlns:local="clr-namespace:DotBeer.UI.WPFClient"
    xmlns:LogicLayer="clr-namespace:DotBeer.Business.Components;assembly=DotBeer.Business.Components"
    xmlns:Toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" 
    xmlns:PresentationLayer="clr-namespace:DotBeer.UI.WPFClient"
    Loaded="UserControl_Loaded" d:DesignWidth="744.756" d:DesignHeight="395.553">
    <UserControl.Resources>
        <ObjectDataProvider x:Key="Vendors" ObjectType="{x:Type business:Vendors}"/>
        <ObjectDataProvider x:Key="ItemsListDS" ObjectType="{x:Type LogicLayer:ItemsList}" d:IsDataSource="True"/>
        <local:LoadImageWithoutLockFileConverter x:Key="imageConverter"/>
    </UserControl.Resources>
    <Grid Name="LayoutRoot" SnapsToDevicePixels="True">
    	<Grid.RowDefinitions>
    		<RowDefinition Height="200"/>
    		<RowDefinition Height="*"/>
    		<RowDefinition Height="40"/>
    	</Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="210"/>
            <ColumnDefinition Width="289.012*"/>
        </Grid.ColumnDefinitions>
        <ListView x:Name="listViewItems" Margin="5,5,5,5" ItemsSource="{Binding Path=Items}" IsSynchronizedWithCurrentItem="True" Style="{DynamicResource ListViewStyle}" KeyUp="listViewItems_KeyUp" Grid.RowSpan="3">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Image" Width="50">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="{Binding Path=ImagePath, Mode=OneWay, Converter={StaticResource imageConverter}}" Width="30" Height="30" Stretch="Uniform" StretchDirection="Both"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="Name" Width="150" DisplayMemberBinding="{Binding Path=Name}"/>
                </GridView>
            </ListView.View>
        </ListView>
        <Grid Grid.Column="1" x:Name="GridInputControls" Grid.RowSpan="1" DataContext="{Binding Path=Items}" d:LayoutOverrides="GridBox">
        	<Grid.ColumnDefinitions>
        		<ColumnDefinition Width="75"/>
        		<ColumnDefinition Width="65" MaxWidth="400"/>
        		<ColumnDefinition Width="75"/>
        		<ColumnDefinition Width="65"/>
        		<ColumnDefinition Width="75"/>
        		<ColumnDefinition Width="65"/>
        		<ColumnDefinition Width="*"/>
        		<ColumnDefinition Width="65"/>
        	</Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="40"/>
				<RowDefinition Height="40"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="40"/>
            </Grid.RowDefinitions>
            <TextBlock HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" Margin="{DynamicResource TextBlockMargin}" Width="Auto" Text="Name:" TextWrapping="Wrap" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}"/>
            <TextBlock HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" Margin="{DynamicResource TextBlockMargin}" Width="67.836" Text="Total cost:" TextWrapping="Wrap" Grid.Row="2" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Grid.Column="4"/>
            <TextBlock HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" Margin="{DynamicResource TextBlockMargin}" Width="67.836" Text="Recipe Cost:" TextWrapping="Wrap" Grid.Row="2" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Grid.Column="2"/>
            <TextBlock HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" Margin="{DynamicResource TextBlockMargin}" Width="67.836" Text="Url:" TextWrapping="Wrap" Grid.Row="3" Grid.RowSpan="1" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}"/>
            <TextBox Margin="{DynamicResource EditControlMargin}" TextWrapping="Wrap" x:Name="TextBoxName" Grid.Column="1" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}" HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" Style="{DynamicResource TextBoxStyle}" Grid.ColumnSpan="7">
                <Binding Path="/Name" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
                    <Binding.ValidationRules>
                        <PresentationLayer:NameValidation></PresentationLayer:NameValidation>
                    </Binding.ValidationRules>
                </Binding>
            </TextBox>
            <TextBox Grid.Row="2" Text="{Binding Path=/TotalCost, Mode=OneWay}" PreviewTextInput="TextBox_PreviewTextInput" TextWrapping="Wrap" x:Name="TextBoxCost" Style="{DynamicResource TextBoxStyle}" Grid.Column="5" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Grid.ColumnSpan="1" IsReadOnly="True" HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" Margin="{DynamicResource EditControlMargin}"/>
            <TextBox Grid.Row="2" Text="{Binding Path=/RecipeCost, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="TextBox_PreviewTextInput" TextWrapping="Wrap" x:Name="TextBoxRecipeCost" Grid.Column="3" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Style="{DynamicResource TextBoxStyle}" Grid.ColumnSpan="1" d:LayoutOverrides="GridBox" HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" Margin="{DynamicResource EditControlMargin}"/>
            <TextBox Margin="{DynamicResource EditControlMargin}" Grid.Row="3" Text="{Binding Path=/Url, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" x:Name="TextBoxUrl" Grid.RowSpan="1" Style="{DynamicResource TextBoxStyle}" Grid.Column="1" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" Grid.ColumnSpan="7"/>
            <TextBlock HorizontalAlignment="Left" Margin="8,0,0,0" Width="Auto" Text="Vendor:" TextWrapping="Wrap" Grid.Row="4" VerticalAlignment="Center"/>
            <ComboBox Margin="{DynamicResource EditControlMargin}" Style="{DynamicResource ComboBoxStyle}" IsSynchronizedWithCurrentItem="True" Grid.Row="4" x:Name="ComboBoxVendor" ItemsSource="{Binding Source={StaticResource Vendors}}" SelectedValue="{Binding Path=/Vendor}" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Grid.Column="1" HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" Grid.ColumnSpan="3"/>
            <TextBlock HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" Margin="{DynamicResource TextBlockMargin}" Width="67.836" Text="Position:" TextWrapping="Wrap" Grid.Row="1" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}" Grid.Column="4"/>
            <TextBox PreviewTextInput="TextBox_PreviewTextInput" Text="{Binding Path=/Position}" TextWrapping="Wrap" x:Name="TextBoxPosition" Grid.Row="1" Style="{DynamicResource TextBoxStyle}" Grid.Column="5" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Margin="{DynamicResource EditControlMargin}" d:LayoutOverrides="GridBox" HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}"/>
            <TextBlock Text="Image:" TextWrapping="Wrap" Grid.Row="1" d:LayoutOverrides="Height" Margin="{DynamicResource TextBlockMargin}" HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}"/>
            <Image Grid.ColumnSpan="1" Grid.RowSpan="1" Width="40" Height="40" Grid.Row="1" Grid.Column="1" Source="{Binding Path=/ImagePath, Mode=OneWay, Converter={StaticResource imageConverter}}" HorizontalAlignment="Left" Margin="5,0,0,0" />
            <Button HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Content="..." Grid.Row="1" Grid.Column="2" Margin="{DynamicResource EditControlMargin}" Style="{DynamicResource ButtonLightStyle}" Height="20" x:Name="ButtonImagePath" Click="ButtonImagePath_Click"/>
            <TextBlock Margin="{DynamicResource TextBlockMargin}" Text="Item cost:" TextWrapping="Wrap" Grid.Row="2" d:LayoutOverrides="Height" HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}"/>
            <TextBox Text="{Binding Path=/Cost, UpdateSourceTrigger=PropertyChanged}" PreviewTextInput="TextBox_PreviewTextInput" TextWrapping="Wrap" x:Name="TextBoxItemCost" Style="{DynamicResource TextBoxStyle}" Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="2" d:LayoutOverrides="Height" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" Margin="{DynamicResource EditControlMargin}"/>
            <CheckBox HorizontalAlignment="{DynamicResource EditControlHorizontalAlignment}" VerticalAlignment="{DynamicResource EditControlVerticalAlignment}" Content="Download image from URL" Grid.Row="4" Grid.Column="5" Style="{DynamicResource CheckBoxStyle}" x:Name="CheckboxDownloadImage" Margin="{DynamicResource EditControlMargin}" Checked="CheckboxDownloadImage_Checked" Unchecked="CheckboxDownloadImage_Unchecked" Grid.ColumnSpan="3" d:LayoutOverrides="GridBox"/>
        </Grid>
        <Grid HorizontalAlignment="Stretch" 
              VerticalAlignment="Stretch" 
              Width="Auto" 
              Height="Auto" 
              Grid.Column="1"
              Name="GridRecipe"
              DataContext="{Binding Path=Items}" Grid.Row="1" Grid.RowSpan="1">
        	<Grid.ColumnDefinitions>
        		<ColumnDefinition Width="142"/>
        		<ColumnDefinition Width="*"/>
        	</Grid.ColumnDefinitions>
        	<Grid.RowDefinitions>
        		<RowDefinition Height="0.5*"/>
        		<RowDefinition Height="0.5*"/>
        	</Grid.RowDefinitions>
        	<TextBlock HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}" Text="Created with:" TextWrapping="Wrap" Grid.Row="0" Margin="{DynamicResource TextBlockMargin}"/>
        	<TextBlock VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}" Text="of following:" TextWrapping="Wrap" Grid.Row="1" Margin="0,0,5,0" HorizontalAlignment="Right"/>
        	<PresentationLayer:NumericUpDown VerticalAlignment="Center" Style="{DynamicResource NumericUpDownStyle}" d:LayoutOverrides="Width" HorizontalAlignment="Left" Height="Auto" Grid.Row="1" x:Name="NumericUpDownAdditionalItemsAmount" Minimum="1" Maximum="10" Value="{Binding Path=/AdditionalItemsAmount, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Margin="28,0,0,0"/>
            <Toolkit:DataGrid x:Name="DataGridCreatedWith" 
                              Grid.Row="0" 
                              Grid.Column="1"
                              AutoGenerateColumns="False"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{Binding Path=/CreatedWithItems}"
                              SelectionMode="Single"
                              ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" 
                              Style="{DynamicResource DataGridStyle}" Margin="5,5,5,5">
                <Toolkit:DataGrid.Columns>
                    <Toolkit:DataGridTemplateColumn Header="Name">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Path=ImagePath}" Margin="5,5,5,5" Width="20" Height="20" Stretch="Uniform" StretchDirection="Both"/>
                                    <TextBlock Text="{Binding Path=Name}" VerticalAlignment="Center" Margin="5,5,5,5"/>
                                </StackPanel>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                        <Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Path=ImagePath}" Margin="5,5,5,5" Width="20" Height="20" Stretch="Uniform" StretchDirection="Both"/>
                                    <ComboBox ItemsSource="{Binding Source={StaticResource ItemsListDS}}"
                                          SelectedValue="{Binding Path=Name}"
                                          Style="{StaticResource ComboBoxStyle}"/>
                                </StackPanel>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    </Toolkit:DataGridTemplateColumn>
                    <Toolkit:DataGridTemplateColumn Header="Amount">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <PresentationLayer:NumericUpDown Style="{DynamicResource NumericUpDownStyle}" Value="{Binding Path=Amount, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Minimum="1" Maximum="10"/>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Toolkit:DataGridTemplateColumn>
                    <Toolkit:DataGridTemplateColumn Header="Replacement">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Path=Replacement.ImagePath}" Margin="5,5,5,5" Width="20" Height="20" Stretch="Uniform" StretchDirection="Both"/>
                                    <TextBlock Text="{Binding Path=Replacement.Name}" VerticalAlignment="Center" Margin="5,5,5,5"/>
                                </StackPanel>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                        <Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Path=Replacement.ImagePath}" Margin="5,5,5,5" Width="20" Height="20" Stretch="Uniform" StretchDirection="Both"/>
                                    <ComboBox ItemsSource="{Binding Source={StaticResource ItemsListDS}}" 
                                          SelectedValue="{Binding Path=Replacement.Name}"
                                          Style="{StaticResource ComboBoxStyle}"/>
                                </StackPanel>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    </Toolkit:DataGridTemplateColumn>
                    <Toolkit:DataGridTemplateColumn Header="Replacement Amount">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <PresentationLayer:NumericUpDown Style="{DynamicResource NumericUpDownStyle}" Value="{Binding Path=Replacement.Amount, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Minimum="1" Maximum="10"/>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                    </Toolkit:DataGridTemplateColumn>
                </Toolkit:DataGrid.Columns>
            </Toolkit:DataGrid>
            <Toolkit:DataGrid x:Name="DataGridAdditionalItems" 
                              Grid.Row="1" 
                              Grid.Column="1"
                              AutoGenerateColumns="False"
                              IsSynchronizedWithCurrentItem="True"
                              ItemsSource="{Binding Path=/AdditionalItems}"
                              SelectionMode="Single"
                              ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" 
                              Style="{DynamicResource DataGridStyle}" Margin="5,5,5,5">
                <Toolkit:DataGrid.Columns>
                    <Toolkit:DataGridTemplateColumn Header="Name">
                        <Toolkit:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Path=ImagePath}" Margin="5,5,5,5" Width="20" Height="20" Stretch="Uniform" StretchDirection="Both"/>
                                    <TextBlock Text="{Binding Path=Name}" VerticalAlignment="Center" Margin="5,5,5,5"/>
                                </StackPanel>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellTemplate>
                        <Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Path=ImagePath}" Margin="5,5,5,5" Width="20" Height="20" Stretch="Uniform" StretchDirection="Both"/>
                                    <ComboBox ItemsSource="{Binding Source={StaticResource ItemsListDS}}" 
                                          SelectedValue="{Binding Path=Name}"
                                          Style="{StaticResource ComboBoxStyle}"/>
                                </StackPanel>
                            </DataTemplate>
                        </Toolkit:DataGridTemplateColumn.CellEditingTemplate>
                    </Toolkit:DataGridTemplateColumn>
                </Toolkit:DataGrid.Columns>
            </Toolkit:DataGrid>
            <TextBlock HorizontalAlignment="{DynamicResource TextBlockHorizontalAlignment}" Text="and" TextWrapping="Wrap" Margin="5,0,0,0" Grid.Row="1" d:LayoutOverrides="Height" VerticalAlignment="{DynamicResource TextBlockVerticalAlignemnt}"/>
        </Grid>
        <Button HorizontalAlignment="Left" Content="Add new item" Style="{DynamicResource ButtonLightStyle}" Margin="5,5,0,5" x:Name="ButtonAddNewItem" Click="ButtonAddNewItem_Click" Width="130" Grid.Column="1" Grid.Row="2" d:LayoutOverrides="GridBox"/>
    </Grid>
</UserControl>
